A double-dimensional array, also known as a two-dimensional array, is an array of arrays. It is a collection of elements arranged in rows and columns, forming a grid-like structure. Each element in a double-dimensional array is identified by two indices - one for the row and another for the column. It is often used to represent matrices and tables in C.
To declare a double-dimensional array in C, you specify the data type of the elements, followedby the array name, and the size of rows and columns in square brackets.
data_type array_name[row_size][column_size];
#include <stdio.h>
int main() {
// Declaration and initialization of a 3x4 integer double-dimensional array
int matrix[3][4] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}
};
// Accessing and printing the elements of the double-dimensional array
printf("Matrix Elements:\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
printf("%d\t", matrix[i][j]);
}
printf("\n");
}
return 0;
}
Matrix Elements:
1 2 3 4
5 6 7 8
9 10 11 12
{{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}}
What is a double-dimensional array in C?
How do you declare a double-dimensional array in C?
What is the purpose of double indexing in arrays?
What is the size of a 2D array defined as 'int arr[3][4]'?
What do you use to iterate through a 2D array row by row in C?